<?php
/* 
Name: postans.php
For posting answers in "Ask A Doctor"
*/
include('../../../wp-blog-header.php');
if ( get_magic_quotes_gpc() ) {
    $_POST      = array_map( 'stripslashes_deep', $_POST );
}
$ans = $_POST['ans'];
$aid = $_POST['aid'];
$myhash = $_POST['h'];

$current_user = wp_get_current_user();
$uid = $current_user->user_login;

if (current_user_can('administrator')):
	if(md5($uid) === $myhash):
		// Basic authentication done
		$podans = array(
					'qid' => $aid,
					'answer' => $ans
					);
		$mypod = pods('answers');

		if($mypod->add($podans)){
			$params = array(
					'orderby' => 't.modified DESC',
					'where' => 't.qid = '.$aid
					);
			$myans = $mypod->find($params);
			//Search for all the answers to that question
			while($myans->fetch()):
			?>
			<div class="qans">
				<?php 
				echo '<span class="ansauth">'.$myans->display('author')." On ".$myans->display('modified')."</span>";
				echo '<span class="ansdesc">'.$myans->display('answer')."</span>";
				?>
			</div>
			<?php
			endwhile;
		}
	endif;
endif;
?>